﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BinAnalysisHelp
{
    public class BinBase
    {
        private string _section;
        private string _address;
        private string _dataexample;
        private string _describe;
        private string _remarks;
        private string _crcold;
        private string _crcnew;
        private string _crchead;
        private string _crctail;
        private string _crclength;
        private byte _original;


        private string _addresspart;
        private string _bigaddr;
        private string _smalladdr;
        private string _bigdata;
        private string _smalldata;
        private string _bigexample;
        private string _smallexample;
        private string _addrbigex;
        private string _addrsmallex;

        private string _module;
        private string _note;

        /// <summary>
        /// 起始地址
        /// </summary>
        public string addresspart
        {
            set { _addresspart = value; }
            get { return _addresspart; }
        }

        /// <summary>
        /// 大端地址数据
        /// </summary>
        public string bigaddr
        {
            set { _bigaddr = value; }
            get { return _bigaddr; }
        }
        /// <summary>
        /// 小端端地址数据
        /// </summary>
        public string smalladdr
        {
            set { _smalladdr = value; }
            get { return _smalladdr; }
        }
        /// <summary>
        /// 大端数据
        /// </summary>
        public string bigdata
        {
            set { _bigdata = value; }
            get { return _bigdata; }
        }

        /// <summary>
        /// 小端数据
        /// </summary>
        public string smalldata
        {
            set { _smalldata = value; }
            get { return _smalldata; }
        }


        /// <summary>
        /// 头加大端数据
        /// </summary>
        public string bigexample
        {
            set { _bigexample = value; }
            get
            {
                if (string.IsNullOrWhiteSpace(_bigexample))
                {
                    return $"0x{bigaddr},0x{Convert.ToUInt32(bigdata, 16).ToString("X2")}";
                }
                else
                {
                    return _bigexample;
                }

            }
        }

        /// <summary>
        /// 头加小端数据
        /// </summary>
        public string smallexample
        {
            set { _smallexample = value; }
            get
            {

                if (string.IsNullOrWhiteSpace(_smallexample))
                {
                    return $"0x{smalladdr},0x{Convert.ToUInt32(smalldata, 16).ToString("X2")}";
                }
                else
                {
                    return _smallexample;
                }


            }
        }

        /// <summary>
        /// 大端地址
        /// </summary>
        public string addrbigex
        {
            set { _addrbigex = value; }
            get
            {
                if (string.IsNullOrWhiteSpace(_addrbigex))
                {
                    return $"{addresspart}{bigaddr}";
                }
                else
                {
                    return _addrbigex;
                }
            }
        }
        /// <summary>
        /// 小端地址
        /// </summary>
        public string addrsmallex
        {
            set { _addrsmallex = value; }
            get
            {
                if (string.IsNullOrWhiteSpace(_addrsmallex))
                {
                    return $"{addresspart}{smalladdr}";
                }
                else
                {
                    return _addrsmallex;
                }
            }
        }
        /// <summary>
        /// 文件原始数据
        /// </summary>
        public byte original
        {
            set { _original = value; }
            get { return _original; }
        }
        /// <summary>
        /// 识别区
        /// </summary>
        public string section
        {
            set { _section = value; }
            get { return _section; }
        }
        /// <summary>
		/// 地址
		/// </summary>
		public string address
        {
            set { _address = value; }
            get { return _address; }
        }
        /// <summary>
        /// 值
        /// </summary>
        public string dataexample
        {
            set { _dataexample = value; }
            get { return _dataexample; }
        }
        /// <summary>
        /// 说明
        /// </summary>
        public string describe
        {
            set { _describe = value; }
            get { return _describe; }
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string remarks
        {
            set { _remarks = value; }
            get { return _remarks; }
        }
        /// <summary>
        /// 旧的crc 校验
        /// </summary>
        public string crcold
        {
            set { _crcold = value; }
            get { return _crcold; }
        }
        /// <summary>
        /// 新的crc 校验
        /// </summary>
        public string crcnew
        {
            set { _crcnew = value; }
            get { return _crcnew; }
        }
        /// <summary>
        /// 该段crc首地址
        /// </summary>
        public string crchead
        {
            set { _crchead = value; }
            get { return _crchead; }
        }
        /// <summary>
        /// 该段crc尾地址
        /// </summary>
        public string crctail
        {
            set { _crctail = value; }
            get { return _crctail; }
        }
        /// <summary>
        /// 该段crc长度例如setting config文件总长度
        /// </summary>
        public string crclength
        {
            set { _crclength = value; }
            get { return _crclength; }
        }
        /// <summary>
        /// 模块
        /// </summary>
        public string module
        {
            set { _module = value; }
            get { return _module; }
        }
        /// <summary>
        /// 说明
        /// </summary>
        public string note
        {
            set { _note = value; }
            get { return _note; }
        }

        /// <summary>
        /// 索引
        /// </summary>
        public int sort { get; set; }

        /// <summary>
        /// 是否是连续Isp地址
        /// </summary>
        public bool IsIsp { get; set; } = false;
        

        /// <summary>
        /// 是否是连续Sensor地址
        /// </summary>
        public bool IsSensor { get; set; } = false;

        public bool IsSetting { get; set; } = false;

        public AddressValueEnum AddrVal { get; set; }

        public string AnalyticalModel { get; set; }


        /// <summary>
        /// 传输
        /// </summary>
        public string TransferHex { get; set; }
        /// <summary>
        /// 视频
        /// </summary>
        public string VideoHex { get; set; }
        /// <summary>
        /// Setting Setting_Idx
        /// </summary>
        public string IdxHex { get; set; }


        


    }

    public class LoadSettingParse
    {

        /// <summary>
        /// 视频制式
        /// </summary>
        public string vName { get; set; }
        /// <summary>
        /// 视频制式值
        /// </summary>
        public uint vHex { get; set; }
        /// <summary>
        /// 传输模式
        /// </summary>
        public string tName { get; set; }
        /// <summary>
        /// 传输模式值
        /// </summary>
        public uint tHex { get; set; }


        /// <summary>
        /// Seting索引
        /// </summary>
        public uint SettingHex { get; set; }
        /// <summary>
        /// Seting所在setting 名称
        /// </summary>
        public string SettingName { get; set; }



        /// <summary>
        /// tve索引
        /// </summary>
        public uint tveHex { get; set; }
        /// <summary>
        /// tve所在setting 名称
        /// </summary>
        public string tveName { get; set; }
        /// <summary>
        /// iq索引
        /// </summary>
        public uint IqHex { get; set; }
        /// <summary>
        /// iq所在setting 名称
        /// </summary>
        public string IqName { get; set; }
        /// <summary>
        /// Sensor索引
        /// </summary>
        public uint SensorHex { get; set; }
        /// <summary>
        /// sensor所在setting 名称
        /// </summary>
        public string SensorName { get; set; }



        public string Note {
            get
            {
                return $"{vName}_0x{vHex.ToString("X")}--{tName}_0x{tHex.ToString("X")}--0x{SettingHex.ToString("X ")}_{SettingName}--0x{tveHex.ToString("X")}_{tveName}--0x{IqHex.ToString("X")}_{IqName}--0x{SensorHex.ToString("X")}_{SensorName}";
            }
        }

    }

}

public enum AddressValueEnum
    {
        Addr = 1,
        Val = 2,
        Other = 3
    }


